﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fiddler;
using System.Windows.Forms;
using System.Windows.Forms.Integration;

namespace BinaryXmlInspector
{
    /// <summary>
    /// Base class for request & response inspectors that decode binary XML (soap+msbin1)
    /// </summary>
    public abstract class BinaryInspector : Inspector2
    {
        private BinaryXmlViewer m_viewer = new BinaryXmlViewer();
        private ElementHost m_host = new ElementHost();

        public override void AddToTab(TabPage tab)
        {   
            m_host.Dock = DockStyle.Fill;
            m_host.Child = m_viewer;
            tab.Controls.Add(m_host);
            tab.Text = Name;
        }

        public override int GetOrder()
        {
            return 1000000000;
        }

        public byte[] body
        {
            get { return m_viewer.VM.EncodedXML; }
            set { m_viewer.VM.EncodedXML = value; }
        }

        public void Clear()
        {
            m_viewer.VM.Clear();
        }

        public bool bDirty
        {
            get { return m_viewer.VM.Dirty; }
        }

        public bool bReadOnly
        {
            get { return m_viewer.VM.ReadOnly; }
            set { m_viewer.VM.ReadOnly = value; }
        }

        public virtual string Name
        {
            get { return "Binary XML"; }
        }

        public override int ScoreForContentType(string sMIMEType)
        {
            return sMIMEType == "application/soap+msbin1" ? 1000000000 : 0;
        }

        public override void SetFontSize(float flSizeInPoints)
        {
            m_viewer.VM.FontSize = flSizeInPoints;
        }

        public override void ShowAboutBox()
        {
            m_viewer.ShowAboutBox();
        }
    }
}
